import { ElMessage } from 'element-plus';

let messageDom: any = null;

const resetMessage = (options: any) => {
    if (messageDom) {
        messageDom.close();
    }
    // eslint-disable-next-line new-cap
    messageDom = ElMessage(options);
};

const typeArr = ['success', 'error', 'warning', 'info'];
typeArr.forEach((type) => {
    resetMessage[type] = (options: any) => {
        if (typeof options === 'string') {
            options = { message: options };
        }
        options.type = type;
        return resetMessage(options);
    };
});

export const message = resetMessage;
